package 临时工具.粮仓.APDU;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class APDUServer {
    public static void main(String[] args) throws Exception {
        ServerSocket server = new ServerSocket(30000);
        System.out.println("服务端启动，等待连接...");

        while (true) {
            Socket socket = server.accept();
            System.out.println("客户端连接：" + socket.getInetAddress());

            InputStream in = socket.getInputStream();
            byte[] buffer = new byte[1024];
            int len = in.read(buffer);

            byte[] received = new byte[len];
            System.arraycopy(buffer, 0, received, 0, len);

            System.out.println("收到APDU数据：");
            APDUUtil.parseAPDU(received);

            OutputStream out = socket.getOutputStream();
            out.write("服务端响应".getBytes());


            socket.close();
        }
    }
}
